package cn.jishiyu11.xeqb.adapter

import android.support.v4.view.PagerAdapter
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView

/**
 * Created by jsy_zj on 2018-03-06.
 */
class HomeViewPagerAdaper constructor(val imgVList: MutableList<ImageView>) : PagerAdapter() {
    //设置viewpager适配器
    override fun isViewFromObject(view: View, any: Any): Boolean {
        return view == any
    }

    override fun getCount(): Int {
        return imgVList!!.size * 10
    }

    override fun destroyItem(container: ViewGroup, position: Int, any: Any) {
        container?.removeView(any as View?)
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
//        container?.removeAllViews()
        container?.addView(imgVList!!.get(position % imgVList!!.size))
        return imgVList?.get(position % imgVList!!.size)
    }
}
